<?php
/**
 * Created by PhpStorm.
 * User: Talent
 * Date: 2018/5/15
 * Time: 15:15
 */
namespace app\index\controller;
use think\Controller;
use app\index\model\Sign;
use app\admin\model\Grade;
use veda\util\Tools;
 class Index extends Controller{
    public function index (){
        return view("index");
    }
    public function sign($class='',$name='',$message=''){
        if(''==$name || ''==$class||''==$message){
            $this->error('班级，姓名或寄语不能为空！');
        }else{
            $user=new Sign;
            $user->p_name=$name;
            $user->p_class=$class;
            $user->p_message=$message;
            $user->create_time=date(Tools::$TIMEFORMAT);
            $user->save();
            $this->save_grade($class);
            if($user->id!=null){
                $this->success('签到成功','index/index/index');
            }

        }

    }
    public function save_grade($class='')
    {
        $grade = Grade::get(["p_grade" => $class]);
        if ($grade == null) {
            $grade = new Grade;
            $grade->p_grade = $class;
            $grade->save();
        }
    }
}